package com.kai.steering.data.service.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.TableName;
import com.kai.steering.data.service.entity.domainObject.QuestionDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;
import java.util.stream.Collectors;

/**
 * <pre>
 * 题目
 * </pre>
 *
 * @author kai
 * @since 2022-02-23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@EqualsAndHashCode(callSuper = false)
@TableName(value = "question")

public class Question implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 题目id
     */
    @TableId(value = "question_id", type = IdType.ID_WORKER)

    private String questionId;


    /**
     * 题目
     */

    private String question;


    /**
     * 创建人管理员id或者用户id
     */

    private String founder;


    /**
     * 创建时间
     */

    private Date creationDatetime;


    /**
     * 题目类型分类
     */

    private String classificationId;


    /**
     * 知识点 以,分割
     */

    private String knowledgeId;


    /**
     * 存在0删除1
     */

    private Integer usable;


    /**
     * 删除日期
     */

    private Date deleteDatetime;
    /**
     * 标准答案
     */
    private String standardAnswer;

    public Question(QuestionDO questionDO) {
       convertQuestion(questionDO);
    }

    public Question convertQuestion(QuestionDO questionDO) {
        this.questionId = questionDO.getQuestionId();
        this.question = questionDO.getQuestion();
        this.founder = questionDO.getFounder();
        this.creationDatetime = questionDO.getCreationDatetime();
        this.classificationId = questionDO.getClassificationDO().getClassificationId();
        if (questionDO.getKnowledgeDOs() != null) {
            this.knowledgeId = questionDO.getKnowledgeDOs().stream().map(knowledgeDO -> {
                return knowledgeDO.getKnowledgeId();
            }).collect(Collectors.joining(","));
        }
        this.usable = questionDO.getUsable();
        this.deleteDatetime = questionDO.getDeleteDatetime();
        return this;
    }
}
